home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_3b.arc / PMDEV.ARC / PMAUXNT.C < prev    next >
C/C++ Source or Header  |  1989-02-14  |  5KB  |  149 lines

  1. /*
  2.  * Initialization module for PMAUX
  3.  *
  4.  * Written by William S. Hall
  5.  * 3665  Benton Street, #66
  6.  * Santa Clara, CA 95051
  7.  *
  8.  */
  9.  
  10. #define INCL_PM
  11. #include <os2.h>
  12. #include <stddef.h>
  13. #include <ttycls.h>
  14. #include <string.h>
  15. #include "pmaux.h"
  16.  
  17. BOOL FAR InitProgram(int argc, char *argv[])
  18. {
  19.  
  20.     char szTitle[50];
  21.     ULONG ctldata;
  22.  
  23.   /* get anchor block handle and message queue handles */
  24.     if ((hAB = WinInitialize(NULL)) == NULL)
  25.     return FALSE;
  26.  
  27.     if ((hmqMsgQ = WinCreateMsgQueue(hAB,0)) == NULL)
  28.         return FALSE;
  29.  
  30.   /* get handle to the local heap so we can use it later */
  31.     if ((hHeap = WinCreateHeap(0, 0, 0, 0, 0, 0)) == NULL)
  32.     return FALSE;
  33.  
  34.   /* This string is needed to register the Window */
  35.     WinLoadString(hAB,NULL, IDS_APPNAME, sizeof(szAppName), (PSZ)szAppName);
  36.  
  37.   /* register window */
  38.     if (!WinRegisterClass(hAB,             /* anchor block handle */
  39.               (PCH)szAppName,     /* class name */
  40.               (PFNWP)MainWndProc,    /* window procedure for class */
  41.               CS_SIZEREDRAW,       /* class styles */
  42.               0))            /* no extra data needed */
  43.     return FALSE;
  44.  
  45.   /* This string is needed to create the frame window */
  46.     WinLoadString(hAB, NULL, IDS_TITLE, sizeof(szTitle), (PSZ)szTitle);
  47.  
  48. #if IBMVER    
  49.     ctldata = FCF_STANDARD & ~FCF_ACCELTABLE & ~FCF_ICON;
  50. #else
  51.     ctldata = FCF_STANDARD;
  52. #endif
  53.  
  54.   /* create window */
  55.     hwndFrame = WinCreateStdWindow(HWND_DESKTOP,    /* parent */
  56.                    WS_VISIBLE,
  57.                    &ctldata,
  58.                                    (PCH)szAppName,    /* class */
  59.                                    (PCH)szTitle,    /* window title */
  60.                                    0L,            /*default client style*/
  61.                                    (HMODULE)NULL,    /* resources in .EXE */
  62.                                    ID_RESOURCE,
  63.                                    (HWND FAR *)&MWnd.hWnd);
  64.                             /* handle to client */
  65.  
  66.   /* fail if creation of either window or video buffer fails */
  67.     if ((hwndFrame == NULL) || (MWnd.pVidBuf == NULL))
  68.     return FALSE;
  69.  
  70.   /* show the window */
  71.     WinShowWindow(hwndFrame, TRUE);
  72.  
  73.   /* set the handle into OS2.ini */
  74.     if (!SetOS2Ini(MWnd.hWnd))
  75.         return FALSE;
  76.  
  77.     return TRUE;
  78. }
  79.  
  80. /* called when client is created */
  81. void FAR WndCreate(HWND hWnd)
  82. {
  83.  
  84.     HPS hPS;
  85.     short width, height, cwidth, cheight;
  86.  
  87.     FONTMETRICS fm[30];
  88.     long cFonts;
  89.     int i;
  90.     short fcid = 0;
  91.          
  92.   /* get the size of an icon */
  93.     xIconsize = WinQuerySysValue(HWND_DESKTOP, SV_CXICON);
  94.     yIconsize = WinQuerySysValue(HWND_DESKTOP, SV_CYICON);
  95.  
  96.   /* load the icon string */
  97.     WinLoadString(hAB, NULL, IDS_ICON, (USHORT)sizeof(szIcon), (PSZ)szIcon);
  98.  
  99.   /* get the system font character metrics */
  100.     hPS = WinGetPS(hWnd);
  101. #if IBMVER
  102.     if (GpiLoadFonts(hAB, "c:\\os2\\dll\\COURIER.FON")) {
  103. #else
  104.     if (GpiLoadFonts(hAB, "FONTS")) {
  105. #endif
  106.         cFonts = 30;
  107.         GpiQueryFonts(hPS,3L,NULL,&cFonts,(LONG)sizeof(FONTMETRICS),fm);
  108.         for (i = 0; i < (short)cFonts; i++) {
  109.             cheight = (short)(fm[i].lMaxBaselineExt + fm[i].lExternalLeading);
  110.             cwidth = (short)fm[i].lMaxCharInc;
  111.         if ((fm[i].fsDefn & 0x8000) && (fm[i].fsType & 1) && (cwidth == 8))
  112.             break;
  113.         }
  114.         if (i < (short)cFonts) {
  115.          fcid = 1;
  116.             ttyfat.usRecordLength  =  sizeof(FATTRS);    
  117.             ttyfat.lMatch      =  fm[i].lMatch;
  118.         ttyfat.fsSelection     =  fm[i].fsSelection;
  119. #if IBMVER
  120.             strcpy(ttyfat.szFacename, fm[i].szFacename);
  121. #else            
  122.             strcpy(ttyfat.szFaceName, fm[i].szFacename);
  123. #endif
  124.             ttyfat.idRegistry     =  fm[i].idRegistry;
  125.             ttyfat.usCodePage     =  850;
  126.             ttyfat.lMaxBaselineExt =  fm[i].lMaxBaselineExt;
  127.             ttyfat.lAveCharWidth =  fm[i].lAveCharWidth;
  128.             ttyfat.fsType      =  FATTR_TYPE_FIXED;
  129.             ttyfat.fsFontUse     =  0;
  130.         }
  131.     }        
  132.  
  133.     if (fcid == 0) {
  134.         GpiQueryFontMetrics(hPS, (LONG)sizeof(FONTMETRICS), &fm[0]);
  135.         cheight = (short)(fm[0].lMaxBaselineExt + fm[0].lExternalLeading);
  136.         cwidth = (short)fm[0].lAveCharWidth;
  137.     }
  138.  
  139.     WinReleasePS (hPS);
  140.  
  141.   /* get other parameters */
  142.     width = (SHORT)WinQuerySysValue(HWND_DESKTOP, SV_CXFULLSCREEN);
  143.     height = (SHORT)WinQuerySysValue(HWND_DESKTOP, SV_CYFULLSCREEN);
  144.  
  145.   /* create the video buffer with the following parameters */
  146.     InitTTYWindow(&MWnd,0,0,width,height,cwidth,cheight,FALSE,TRUE,TRUE,
  147.                                     fcid,0xff);
  148. }
  149.